tg-me.com/python12/1306
Last Update:
# پاسخ تمرین شماره 2
eq = ""
result = 0
op = "+"
loopsFirstRun = True
while True:
if loopsFirstRun != True:
op = input("Enter an operator (+,-,*,/,=) : ") # دریافت علامت
eq = "(" + eq + op;
if op == "=":
break
num = float(input("Enter a number : ")) # دریافت عدد
if op == "+":
result = result + num
elif op == "-":
result = result - num
elif op == "*":
result = result * num
elif op == "/":
result = result / num
else: # در صورتی که علامت وارد شده از چهار عمل اصلی نباشد
result = "Invalid operator : " + op # نمایش پیغام خطا
eq = eq + str(num);
if loopsFirstRun != True:
eq = eq + ")";
print(eq + " = " + str(result))
loopsFirstRun = False
print(result)
BY پایتون / python
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
Share with your friend now:
tg-me.com/python12/1306